<?php
	require_once ("db_connection.php");
	
		$afid = $_GET['afid'];
		$search = $_GET['term'];
		if( !$search ){
			$result = mysql_query("SELECT * FROM vehicles WHERE vehiclemodel LIKE '%". mysql_real_escape_string($search)."%' AND affiliateid='$afid'", $con);
		}else{
			$result = mysql_query("SELECT * FROM vehicles WHERE affiliateid='$afid'", $con);
		}
		
		$data = array();
		while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ){
			$data[] = array(
				'label' => $row['vehiclemodel'] ,
				'value' => $row['vehiclemodel'],
				'vtype' => $row['vehicletype']
			);
		}
		
		mysql_close($con);
		
		echo json_encode($data);
		flush();
?>